#include "cgic.h"
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "session.h"
#include "cgi_interface.h"
#include "global_val.h"

// 接口参数：
// 1.room_id
// 2.method
// 3.method = set暂时不支持 只能get

int cgiMain() {
	
	char sfp[256];
	//create session file
	strcpy(sfp,"/tmp/sess_123456");
	//strcat(sfp,"/sess_");
	//strcat(sfp,session_id);
	
	FILE *sf = fopen(sfp,"w");
	chmod(sfp,06777);
	
	int res = open("/tmp/session_123", O_CREAT|O_WRONLY, 0677);
	if(res==-1)
	{
		perror("open:");
	}
	
	cgiHeaderContentType("text/html");
	
	fprintf(cgiOut,"res=%d\n", res);
	
	if( sf == NULL){
		fprintf(cgiOut,"sf == NULL");
		return NULL;
	}
	
	//write session file

	fputs("https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif",sf);

	fclose(sf);
	
	fprintf(cgiOut,"SUCCESS");
	
	
	
	return 0;
	
}


